package com.zbw.mqtt;

import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.nio.charset.StandardCharsets;

public class PublishMessage {

    private Server server;

    @Before
    public void setUp() throws MqttException {
        this.server = new Server();
    }

    @After
    public void tearDown() throws MqttException {
        this.server.close();
        this.server = null;
    }

    @Test
    public void publish() throws MqttException {
        MqttMessage message = new MqttMessage("some message to be published".getBytes(StandardCharsets.UTF_8));
        message.setRetained(true);
        message.setQos(1);
        this.server.publish(message);
    }
}
